package com.daikin.ktmustwrite.ui.fragment.tree

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.daikin.ktmustwrite.R
import com.daikin.ktmustwrite.app.base.BaseFragment
import com.daikin.ktmustwrite.app.ext.bindViewPager2
import com.daikin.ktmustwrite.app.ext.init
import com.daikin.ktmustwrite.app.util.CacheUtil
import com.daikin.ktmustwrite.databinding.FragmentViewpagerBinding
import com.daikin.ktmustwrite.viewmodel.state.TreeViewModel
import kotlinx.android.synthetic.main.include_viewpager.*
import me.hgj.jetpackmvvm.ext.nav
import me.hgj.jetpackmvvm.ext.navigateAction

class TreeArrFragment : BaseFragment<TreeViewModel, FragmentViewpagerBinding>() {
    var titleData = arrayListOf("广场", "每日一问", "体系", "导航")
    private var fragments :ArrayList<Fragment> = arrayListOf()
    init {
        fragments.add(PlazaFragment())
        fragments.add(AskFragment())
        fragments.add(SystemFragment())
        fragments.add(NavigationFragment())
    }

    override fun layoutId(): Int {
        return R.layout.fragment_viewpager
    }

    override fun initView(savedInstanceState: Bundle?) {
        include_viewpager_toolbar.run {
            inflateMenu(R.menu.todo_menu)
            setOnMenuItemClickListener {
                when(it.itemId){
                    R.id.todo_add ->{
                        if(CacheUtil.isLogin()){
                        }else{
                        }
                    }
                }
                true
            }
        }
    }

    override fun lazyLoadData() {
        view_pager.init(this,fragments).offscreenPageLimit=fragments.size
        //初始化 magic_indicator
        magic_indicator.bindViewPager2(view_pager, mStringList = titleData) {
            if (it != 0) {
                include_viewpager_toolbar.menu.clear()
            } else {
                include_viewpager_toolbar.menu.hasVisibleItems().let { flag ->
                    if (!flag) include_viewpager_toolbar.inflateMenu(R.menu.todo_menu)
                }
            }
        }
    }

    override fun createObserver() {

    }


}